package com.ulinkle.ulinkle_muhf.service;

import android.app.Application;
import android.content.Context;
import android.text.TextUtils;

import com.blankj.utilcode.util.LogUtils;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

/**
 * @Description: java类作用描述
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class App extends Application {
   /**
     * 单例   Single case
     */
    private static App app;
    @Override
    public void onCreate() {
        super.onCreate();
        LogUtils.getConfig().setGlobalTag("UHFDemo")
                .setLogSwitch(true)
                .setLog2FileSwitch(true)
                .setDir("sdcard/UHF/log/")
                .setSaveDays(10);
        app = this;
        Context context = getApplicationContext();
        // 获取当前包名   Gets the current package name
        String packageName = context.getPackageName();
        // 获取当前进程名  Gets the current process name
        String processName = getProcessName(android.os.Process.myPid());
    }




      /**
     * 获取进程号对应的进程名
     * Gets the process name corresponding to the process number
     *
     * @param pid
     *         进程号
     *
     * @return 进程名
     */
    private static String getProcessName(int pid) {
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader("/proc/" + pid + "/cmdline"));
            String processName = reader.readLine();
            if (!TextUtils.isEmpty(processName)) {
                processName = processName.trim();
            }
            return processName;
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException exception) {
                exception.printStackTrace();
            }
        }
        return null;
    }
}
